/**
 * 重置密码
 */
import React, { Component } from 'react';
import { Button, Modal, Checkbox, Form, Input, Upload, message, Icon } from 'antd';
import { connect } from 'dva';
// import md5 from '../../components/md5';
const FormItem = Form.Item;

const styles = {
	main: {
		display: 'inline'
	},
	but: {
		marginRight: '1em'
	},
	spn:{
		width:'20%',
		marginLeft: '1em',
		textAlign: 'center',
		lineHeight:'2em',
	},
	ipt:{
		width:'50%'
	},
	flx:{
		display:'-webkit-flex',
		display:'flex',
	}
};
const formItemLayout = {
    labelCol: {
      span: 6,
    },
    wrapperCol: {
      span: 14,
    }
  };

class ResetPwd extends Component {

	constructor(props, context) {
		super(props, context);
		this.state = {
            confirmDirty: false,
		};
    }
    handleConfirmBlur = (e) => {
        const value = e.target.value;
        this.setState({ confirmDirty: this.state.confirmDirty || !!value });
      }
    checkPassword = (rule, value, callback) => {
        const form = this.props.form;
        if (value && value !== form.getFieldValue('password01')) {
          callback('两次密码不一致');
        } else {
          callback();
        }
      }
    checkConfirm = (rule, value, callback) => {
        const form = this.props.form;
        if (value && this.state.confirmDirty) {
          form.validateFields(['password02'], { force: true });
        }
        callback();
    }
    onReset = () =>{
       
        const form = this.props.form;
        const { dispatch, personal, closeModal} = this.props;
        const { userDetData,resent } = personal;
        const password = localStorage.getItem('password');
        let data ={}; 
        // form.validateFields((err, values) => {
        //   if (err) {
        //     return;  
        //   }
        //       data = {    
        //         "newPassword": md5(values.password01).substring(8, 24),
        //         "oldPassword": md5(values.oldPassword).substring(8, 24),
        //   }
        //   dispatch({
        //       type:'personal/resetPsw',
        //       payload:data,
        //   })
        // form.resetFields();
        // if(password === data.oldPassword){
        //     closeModal();
        // }else{
        //     return;
        // }
        // });
    }
    

// 
	render() {
        const {visible ,closeModal, form} = this.props;
        const { getFieldDecorator } = form;
        return (
            <Modal
                visible={visible}
                title="重置密码"
                okText="确认"
                onCancel={closeModal}
                onOk={this.onReset}
            >
                <Form>
                    <FormItem label="请输入原密码" {...formItemLayout}>
                        {getFieldDecorator('oldPassword', {
                            rules: [{ required: true, message: '请输入原密码' }]
                        })(
                            <Input placeholder="请输入原密码" />
                        )}
                    </FormItem>
                    <FormItem label="请输入新密码" {...formItemLayout}>
                        {getFieldDecorator('password01', {
                            rules: [{ required: true, message: '请输入新密码' }]
                        })(
                            <Input placeholder="请输入新密码" />
                        )}
                    </FormItem>
                    <FormItem label="请再次输入新密码" {...formItemLayout}>
                        {getFieldDecorator('password02', {
                            rules: [{ required: true, message: '请再次输入新密码' }]
                        })(
                            <Input placeholder="请输入新密码" onBlur={this.handleConfirmBlur} />
                        )}
                    </FormItem>
                </Form>
            </Modal>
        )
	}
}
export default Form.create()(connect(({ userCenter }) => ({ userCenter }))(ResetPwd));
